package com.wd.tech.adapter.News;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.wd.tech.R;
import com.wd.tech.bean.News_Plate_Channel_Bean;
import com.wd.tech.view.activity.News_ChannelActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * date:2020/7/2
 * author:王成虎(13671)
 * month:七月
 * function:
 */
public class PlateMoreAdapter extends RecyclerView.Adapter<PlateMoreAdapter.PlateMoreHolder> {


    private Context context;
    private List<News_Plate_Channel_Bean.ResultBean> list;
    private SharedPreferences newsid;

    public PlateMoreAdapter(Context context, List<News_Plate_Channel_Bean.ResultBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public PlateMoreHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.plate_more_layout, parent, false);
        return new PlateMoreHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PlateMoreHolder holder, int position) {
        /*Glide.with(context)
                .load(list.get(position).getPic())
                .circleCrop()
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))
                .into(holder.plateImage);*/
        holder.plateImage.setImageURI(list.get(position).getPic());
        holder.plateName.setText(list.get(position).getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, News_ChannelActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                newsid = context.getSharedPreferences("Channelid", Context.MODE_PRIVATE);
                newsid.edit().putInt("Channel_id",list.get(position).getId()).commit();
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class PlateMoreHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.plate_image)
        SimpleDraweeView plateImage;
        /*@BindView(R.id.plate_image)
        ImageView plateImage;*/
        @BindView(R.id.plate_name)
        TextView plateName;
        @BindView(R.id.plate_js)
        TextView plateJs;

        public PlateMoreHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
